package controllers;

import java.util.List;

import controllers.CRUD.ObjectType;
import play.db.Model;
import play.exceptions.TemplateNotFoundException;
import play.mvc.With;
import models.LendCard;
import models.LendCardF;

@With(Secure.class)
@CRUD.For(LendCardF.class)
public class LendCardFAction extends CRUD{
	
	  @Check("UserControl")
	  public static void list(int page, String search, String searchFields, String orderBy, String order) {
	        ObjectType type = ObjectType.get(getControllerClass());
	        notFoundIfNull(type);
	        if (page < 1) {
	            page = 1;
	        }
	        List<Model> objects = type.findPage(page, search, searchFields, orderBy, order, (String) request.args.get("where"));
	        Long count = type.count(search, searchFields, (String) request.args.get("where"));
	        Long totalCount = type.count(null, null, (String) request.args.get("where"));
	        try {
	            render(type, objects, count, totalCount, page, orderBy, order);
	        } catch (TemplateNotFoundException e) {
	            render("CRUD/list.html", type, objects, count, totalCount, page, orderBy, order);
	        }
	    }
	  
	  public static void savemoney(String moneyt,String lnum){
		  int state = 0 ;
		  System.out.println(lnum+"-------------"+moneyt);
		  try{
			  LendCard lendcard = LendCard.find("from LendCard where lecnum = ?", lnum).first();
			  lendcard.lecmone = Double.parseDouble(moneyt);
			  lendcard.save();
			  state = 1 ;
			  render(state);
		  }catch(Exception e){
			  state = 0 ;
			  e.printStackTrace();
			  render(state);
		  }
	  }
	  
}
